import { MatIconRegistry } from '@angular/material';
import { DomSanitizer } from '@angular/platform-browser';

/**
 * @user: 180300
 * @date: 2018/4/17 15:54
 * @description: svg转icon图标字体util
 *
 */
export const loadSvgResources = (iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) => {
  const imgDir = 'assets/img';
  const sidebarDir = `${imgDir}/sidebar`;
  const daysDir = `${imgDir}/days`;
  const avatarDir = `${imgDir}/avatar`;
  const iconsDir = `${imgDir}/icons`;

  // sidebar icon 注册
  iconRegistry.addSvgIcon(
    'day',
    sanitizer.bypassSecurityTrustResourceUrl(`${sidebarDir}/day.svg`));
  iconRegistry.addSvgIcon(
    'month',
    sanitizer.bypassSecurityTrustResourceUrl(`${sidebarDir}/month.svg`));
  iconRegistry.addSvgIcon(
    'week',
    sanitizer.bypassSecurityTrustResourceUrl(`${sidebarDir}/week.svg`));
  iconRegistry.addSvgIcon(
    'project',
    sanitizer.bypassSecurityTrustResourceUrl(`${sidebarDir}/project.svg`));
  iconRegistry.addSvgIcon(
    'projects',
    sanitizer.bypassSecurityTrustResourceUrl(`${sidebarDir}/projects.svg`));
  // icons 注册
  iconRegistry.addSvgIcon(
    'move',
    sanitizer.bypassSecurityTrustResourceUrl(`${iconsDir}/move.svg`));
  iconRegistry.addSvgIcon(
    'add',
    sanitizer.bypassSecurityTrustResourceUrl(`${iconsDir}/add.svg`));
  iconRegistry.addSvgIcon(
    'delete',
    sanitizer.bypassSecurityTrustResourceUrl(`${iconsDir}/delete.svg`));

  // days icon 注册
  const days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
    11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
  days.forEach(
    day =>
      iconRegistry.addSvgIcon(
    `day${day}`,
    sanitizer.bypassSecurityTrustResourceUrl(`${daysDir}/day${day}.svg`))
  );
  // avatar icon
  const avatars = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  days.forEach(
    num =>
      iconRegistry.addSvgIcon(
        `icons${num}`,
        sanitizer.bypassSecurityTrustResourceUrl(`${avatarDir}/icons${num}.svg`))
  );
}
